from django.http import JsonResponse
from django.shortcuts import render
from django.views import View


class CookieView(View):
    def get(self, request):
        # 1.设置cookie
        response = JsonResponse({'data': '操作cookie'})
        # 单位秒
        # response.set_cookie('IT', 'heima', max_age=3600 * 24 * 30)

        # 2.读取cookie ==>dict
        cookie = request.COOKIES
        print(cookie)

        # 3.删除cookie
        response.delete_cookie('IT')
        return response

class SessionView(View):
    def get(self, request):

        response = JsonResponse({'data': '操作cookie'})


        # 1.设置session
        # 默认过期时间 是 2周
        # request.session['k'] = 'heima'
        # request.session.set_expiry(3600)

        # 单位秒

        # 2.读取session ==>dict
        # print(request.session['k'])


        # 3.删除session
        request.session.flush()

        return response
